// pages/moban/moban.js
const app = getApp();
let animationShowHeight = 0;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    xs_3:"display:none",
    xs_2:"display:none",
    xs_1:"display:block;margin-top:50px",
    xs_4:"display:none",
    xs_5:"margin-top:50px",
    xs_6:"margin-top:110px",
    xs_7:"margin-top:155px",
    xs_33:"display:none",
    animation: '',
    EventEmitter:[],
    navScrollLeft: 0,
    navScrollLeft1: 0,
 
    currentTab1:0,
    hidden: true,
    zj_yc:"display:none",
    zj_yc1:"display:inline-block",
    xianshi:"display:none",
    tui_j:[],
    countdown: '',
    listData: [],
    currentUrlIndex: 0,
    articles: [],
    hidden: true,
    loadingData: false,
    show:false,
    EventEmitter:[],
    navScrollLeft: 0,
    winWidth: 0,
    winHeight: 0, 
    currentTab:0,
    currentUrlIndex: 0,
    articles: [],
    loadingData: false,
  },
  loadData: function(tail, callback) {
    if(app.globalData.lishi ==undefined){
      app.globalData.lishi=0
    }
     var that = this,
      urlIndex = that.data.currentUrlIndex;
      if(urlIndex==0){
        urlIndex=1
      }
      var shul = 20*1*urlIndex*1
      console.log(shul)
      app.globalData.shul = shul
      var that = this
      wx.request({
        url: app.globalData.url_l + 'api/member/moban_list',
      method: 'post',
      data:{
          uid:app.globalData.uid,
          shu:app.globalData.shul,
          state:app.globalData.shu,
          lei:app.globalData.curr,
          content:app.globalData.qshu1
      },
        method: 'post',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          console.log(222222222)
          console.log(res)
          if(res.data.data.length==0){
            wx.showToast({
              title: "没有更多数据！",
              icon: 'none',
              duration: 2000
            })
          }
            wx.hideNavigationBarLoading();
            wx.stopPullDownRefresh();
            if(res.data.shi==""){
              that.setData({
                meiyougengdu: "display:block"
              })
            }
            var oldArticles =that.data.tui_j,
            newArticles = tail ? oldArticles.concat(res.data.data) : res.data.data;
            app.globalData.cd_id1=newArticles.length
            var shi_dj = [];
          app.globalData.po=(urlIndex + 1) >= res.data.data.length? 0 : urlIndex + 1
          console.log(newArticles)
          that.setData({
            
            tui_j:newArticles,
            currentUrlIndex: (urlIndex + 1) >= res.data.data.length ? 0 : urlIndex + 1,
            sj_xz:"display:none",
            sj_xz1:"display:none",
          });
          wx.hideNavigationBarLoading();
          wx.stopPullDownRefresh();
          if (callback) {
            callback();
          }
        },
      })
  // }
  },
  
  // /**
  //  * 监听用户下拉动作
  //  */
  onPullDownRefresh: function() {
    var that = this
  wx.request({
    url: app.globalData.url_l + 'api/member/moban_list',
    method: 'post',
    data:{
        uid:app.globalData.uid,
        shu:0,
        state:app.globalData.shu,
        lei:app.globalData.curr,
        content:app.globalData.qshu1
    },
    timeout:3000,
    method: 'post',
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    success: function (res) {
      console.log(11111111)
      console.log(res)
         wx.hideNavigationBarLoading();
         wx.stopPullDownRefresh();
        // app.globalData.huancun = res.data.list
        that.setData({
          tui_j:res.data.data
        })
        //that.setCountDown();
     
    },
  })
  
  wx.showToast({
    title: "数据加载中...",
    icon: 'loading',
    duration: 2000
  })
  
  },
  onReachBottom:function(){
    console.log("触底了");
    console.info('onReachBottom');
  var hidden = this.data.hidden,
    loadingData = this.data.loadingData,
    that = this;
  if (hidden) {
    this.setData({
      hidden: false
    });
    //console.info(this.data.hidden);
  }
  if (loadingData) {
    return;
  }
  this.setData({
    loadingData: true
  });
  // 加载数据,模拟耗时操作
  wx.showToast({
    title: "数据加载中...",
    icon: 'loading',
    duration: 2000
  });
  
  setTimeout(function() {
    that.loadData(true, () => {
      that.setData({
        hidden: true,
        loadingData: false
      });
    });
     console.info('上拉数据加载完成.');
    }, 1000);
  },
  ht:function(e){
    var that = this;
    var he_id = e.currentTarget.dataset.id; 
    wx.navigateTo({
      url: '../moban_doc/moban_doc?mb_id='+he_id,
    })
  },
  het:function(e){
    var that = this;
    var he_id = e.currentTarget.dataset.id; 
    wx.navigateTo({
      url: '../xq_wendang/xq_wendang?he_id='+he_id,
    })
  },
  mb_zx:function(e){
    var mb_id = e.currentTarget.dataset.mb_id; 
    console.log(mb_id)
    wx.navigateTo({
      url: '../moban_doc/moban_doc?mb_id='+mb_id,
    })
  },
  can_zk:function(e){
     var that = this;
     console.log(22)
     this.setData({
      xianshi:"display:block"
    })
    //  var animation = wx.createAnimation({
    //   transformOrigin: "50% 50%",
    //   duration: 2000,
    //   timingFunction: "ease",
    //   delay: 0
    // })
    // this.animation = animation
    // // animation.opacity(1).translateY(100, 0).step()
    // animation.translateY(animationShowHeight).step()
    // this.setData({
    //   animation: animation.export(),
    //   xianshi:"display:block"
    // })
  },
  guanbi:function(e){
    var that = this;
    this.setData({
      xianshi:"display:none"
    })
   
 },
  switchNav(event){
    var that = this;
    var cur = event.currentTarget.dataset.current;
    console.log(app.globalData.uid)
    if(cur==0){
      app.globalData.shu = 1;
      that.setData({
        xs_1:"display:block;margin-top:50px",
        xs_2:"display:none",
        xs_3:"display:none",
        xs_33:"display:none",
        xs_4:"display:none",
      })
    }else if(cur==1){
      app.globalData.shu = app.globalData.corpid;
      that.setData({
        xs_2:"display:block;margin-top:110px",
        xs_1:"display:none",
        xs_3:"display:none",
        xs_33:"display:none",
        xs_4:"display:block",
      })
    }else if(cur==2){
      app.globalData.shu = 2;
      that.setData({
        xs_3:"display:block;margin-top:155px",
        xs_2:"display:none",
        xs_1:"display:none",
        xs_33:"display:block",
        xs_4:"display:block",
      })
    }
    wx.request({
      url: app.globalData.url_l + 'api/member/moban_list',
      method: 'post',
      data:{
          uid:app.globalData.uid,
          state:app.globalData.shu,
          shu:0,
          lei:'',
          content:app.globalData.qshu1
      },
      timeout:3000,
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(11111111)
        console.log(res)
           wx.hideNavigationBarLoading();
           wx.stopPullDownRefresh();
          // app.globalData.huancun = res.data.list
          that.setData({
            tui_j:res.data.data
          })
          //that.setCountDown();
       
      },
    })
    var singleNavWidth = this.data.windowWidth / 5;
    console.log((cur - 2) * singleNavWidth)
    this.setData({
        navScrollLeft: (cur - 2) * singleNavWidth
    }) 
    if (this.data.currentTab == cur) {
        return false;
    } else {
        this.setData({
            currentTab: cur
        })
    }
},

switchNav1(event){
  var that = this;
  var cur = event.currentTarget.dataset.current1; 
  console.log(cur)
  app.globalData.curr= cur
  wx.request({
    url: app.globalData.url_l + 'api/member/moban_list',
    method: 'post',
    data:{
        uid:app.globalData.uid,
        state:app.globalData.shu,
        shu:0,
        lei:cur,
        content:app.globalData.qshu1
    },
    timeout:3000,
    method: 'post',
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    success: function (res) {
      console.log(11111111)
      console.log(res)
         wx.hideNavigationBarLoading();
         wx.stopPullDownRefresh();
        // app.globalData.huancun = res.data.list
        that.setData({
          tui_j:res.data.data,
          xianshi:"display:none"
        })
        //that.setCountDown();
     
    },
  })

  var singleNavWidth1 = this.data.windowWidth / 5;
  var tu = (cur - 2) * singleNavWidth1
  console.log(tu)
  this.setData({
    navScrollLeft1: (cur - 2) * singleNavWidth1+40
  })      
  if (this.data.currentTab1 == cur) {
      return false;
  } else {
      this.setData({
          currentTab1: cur
      })
  }
},

qs_i:function(e){
  console.log(e.detail.value)
  app.globalData.qshu1 = e.detail.value
},
sou:function(){
  var that = this;
  wx.request({
    url: app.globalData.url_l + 'api/member/moban_list',
    method: 'post',
    data:{
        uid:app.globalData.uid,
        shu:0,
        state:app.globalData.shu,
        lei:app.globalData.curr,
        content:app.globalData.qshu1
    },
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    success: function (res) {
      console.log(res)
      that.setData({
          tui_j:res.data.data,
          mb_list:res.data.lei
      })
    }
  })
},

qs_i1:function(e){
  console.log(e.detail.value)
  app.globalData.qshu2 = e.detail.value
},
sou1:function(){
  var that = this;
  
},

switchTab(event){
  var cur = event.detail.current;
  var singleNavWidth = this.data.windowWidth / 5;
  this.setData({
      currentTab: cur,
      navScrollLeft: (cur - 2) * singleNavWidth
  });
},

fuzhi:function(event){
  var fz = event.currentTarget.dataset.fz; 
  wx.setClipboardData({
    data: fz,
    success: function (res) {
     // console.log(res)
        wx.showModal({
        title: '提示',
        content: '复制成功',
        showCancel: false
        });
    }
    })
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  var that = this;
  app.globalData.curr = '',
  app.globalData.qshu1 = ''
  wx.request({
    url: app.globalData.url_l + 'api/member/moban_list',
    method: 'post',
    data:{
        uid:app.globalData.uid,
        state:1,
        shu:0,
        lei:'',
        content:app.globalData.qshu1
    },
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    success: function (res) {
      console.log(res)
      that.setData({
          tui_j:res.data.data,
          mb_list:res.data.lei
      })
    }
  })
  wx.request({
    url: app.globalData.url_l + 'api/member/url',
    method: 'post',
    data:{},
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    success: function (res) {
      console.log(res)
      that.setData({
          lianjie:res.data
      })
    }
  })
  wx.getSystemInfo({
      success: (res) => {
          this.setData({
              pixelRatio: res.pixelRatio,
              windowHeight: res.windowHeight,
              windowWidth: res.windowWidth
          })
      },
  }) 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if(app.globalData.sc==2){
      wx.showModal({
        title: '温馨提示',
        content:app.globalData.sc_ts,
        success (res) {
          if (res.confirm) {
            wx.switchTab({
              url: '../index/index',
            })
          } else if (res.cancel) {
            wx.switchTab({
              url: '../index/index',
            })
          }
        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})